package test6;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2023-04-05
 * Time: 15:52
 */
import java.util.*;
//https://www.nowcoder.com/practice/365d5722fff640a0b6684391153e58d8?tpId=182&tqId=34783&ru=/exam/oj
class Gloves {
    public int findMinimum(int n, int[] left, int[] right) {
        // write code here
        int leftNum = 0;
        int leftMin = Integer.MAX_VALUE;
        int rightMin = Integer.MAX_VALUE;
        int rightNum = 0;
        int sum = 0;
        for (int i = 0; i < n; i++) {
            if (left[i] * right[i] == 0) {
                sum += left[i] + right[i];
            } else {
                leftNum += left[i];
                if (leftMin > left[i]) {
                    leftMin = left[i];
                }
                rightNum += right[i];
                if (rightMin > right[i]) {
                    rightMin = right[i];
                }
            }
        }
        return Math.min(leftNum - leftMin, rightNum - rightMin) + sum + 2;
    }
}
